package com.guigu.zj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.mapper.JbMapper;
import com.guigu.mapper.SerialcodingMapper;
import com.guigu.mapper.YyisitroomMapper;
import com.guigu.pojo.Jb;
import com.guigu.pojo.Serialcoding;
import com.guigu.pojo.Yyisitroom;
import com.guigu.zj.pojo.PageVo;
import com.guigu.zj.service.JbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class JbServiceImpl implements JbService {
    @Autowired
    JbMapper jbMapper;
    @Autowired
    YyisitroomMapper yMapper;
    @Autowired
    SerialcodingMapper serialcodingMapper;
    public PageVo<Jb> queryAll(PageVo<Jb> pageVo) {
        PageHelper.startPage(pageVo.getPage(),pageVo.getNum());
        List<Jb> jbs = jbMapper.queryAll(pageVo);
        PageInfo jbPageInfo = new PageInfo(jbs);
        long total = jbPageInfo.getTotal();
        PageVo<Jb> vo = new PageVo<Jb>();
        vo.setTotal(total);
        vo.setRows(jbs);
        return vo;

    }
    public List<Yyisitroom> find() {
        return yMapper.find();
    }

    public int insertSelective(Jb record) {
        Serialcoding s = serialcodingMapper.find();
        record.setBm("jb00"+(s.getJbid()+1));
        Serialcoding serialcoding = new Serialcoding();
        serialcoding.setJbid(s.getJbid()+1);
        serialcodingMapper.update(serialcoding);
        return jbMapper.insertSelective(record);
    }

    public Jb selectByPrimaryKey(Integer id) {
        return jbMapper.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(Jb record) {
        return jbMapper.updateByPrimaryKeySelective(record);
    }

    public int deleteByPrimaryKey(Integer id) {
        return jbMapper.deleteByPrimaryKey(id);
    }
}
